/**
 * @author Gerd Wagner, Linda Eckardt
 * @constructor
 * @this {NumberRange}
 * @param {number}
 *          lb The lower bound of the number range.
 * @param {number}
 *          ub The upper bound of the number range.
 * @param {number}
 *          lbD The lower bound of the number range for fractions.
 * @param {number}
 *          ubD The upper bound of the number range for fractions.
 */
function NumberRange(
    lb,   // lower bound (Integer, mandatory)
    ub,   // upper bound (Integer, mandatory)
    lbD,  // lower bound denominator (Integer)
    ubD   // upper bound denominator (Integer)
) {
  this.lb = 0;
  this.ub = 0;

  if (arguments.length > 0) { // constructor invocation with arguments
    try {
      this.setLb( lb);
      this.setUb( ub);
      if (arguments.length > 2) {
        this.setLbD( lbD);
        this.setUbD( ubD);
      }
    } catch (e) {
      view.consoleOutput(e.name + ": " + e.message, MessageType.Error);
    }
  }
}
NumberRange.prototype.setLb = function(lb) {
  if (lb === undefined) {
    throw new MandatoryValueConstraintViolation("No value provided for lb!");
  } else if (!util.isInteger(lb)) {
    throw new TypeConstraintViolation("The value of lb is not an integer!");
  } else
    this.lb = lb;
};
NumberRange.prototype.setUb = function(ub) {
  if (ub === undefined) {
    throw new MandatoryValueConstraintViolation("No value provided for ub!");
  } else if (!util.isInteger(ub)) {
    throw new TypeConstraintViolation("The value of ub is not an integer!");
  } else if (ub < this.lb) {
    throw new ValueRangeConstraintViolation(
        "The upper bound is smaller than the lower bound!");
  } else
    this.ub = ub;
};
NumberRange.prototype.setLbD = function(lbD) {
  if (lbD === undefined) {
    throw new MandatoryValueConstraintViolation("No value provided for lbD!");
  } else if (!util.isInteger(lbD)) {
    throw new TypeConstraintViolation("The value of lbD is not an integer!");
  } else
    this.lbD = lbD;
};
NumberRange.prototype.setUbD = function(ubD) {
  if (ubD === undefined) {
    throw new MandatoryValueConstraintViolation("No value provided for ubD!");
  } else if (!util.isInteger(ubD)) {
    throw new TypeConstraintViolation("The value of ubD is not an integer!");
  } else if (ubD < this.lbD) {
    throw new ValueRangeConstraintViolation(
        "The upper bound denominator is smaller than the lower bound denominator!");
  } else
    this.ubD = ubD;
};
